#ifndef TRACTASKLISTCONTROLLER_H
#define TRACTASKLISTCONTROLLER_H

#include "../tasktop4qtcreator/tasklistcontroller.h"
#include <QtCore/QUrl>
#include <QtGui/QMenu>
#include <QtGui/QWidget>
#include <QtCore/QAbstractItemModel>
#include <QSortFilterProxyModel>
#include "traccreatequerydialog.h"
#include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include "ticket.h"

namespace ProjectExplorer {
class Project;
}
//class QAbstractItemModel;
class TaskListControllerPrivate;
//class QSortFilterProxyModel;
class ITicketBackendConfiguration;
class TicketError;
class BaseTicketItemModel;
class TracTaskListController : public TaskListController
{
    Q_OBJECT
public:
    TracTaskListController();
    ~TracTaskListController();

signals:
    void onModelChanged(TaskListRoot *taskListRoot);
    void onVersionChanged(QString version);
    void onError(Error *error);
    void onImageChanged(TaskImage *image);
    void onContainerChanged(TaskContainer *container);
    void onTaskChanged(TaskHandle *task);
    void onUiServiceCallFinished();

public slots:
    void root();
    void container(QString identifier);
    void syncVersion();
    void syncContainer(QString identifier);
    void getImage(QString identifier);
    void openTask(TaskHandle *task);
    void openTaskById(QString taskId, QString repoUrl);
    void newTask(bool isLocal);
    void syncRoot();
    void syncTask(QString identifier);
    void markTaskRead(TaskHandle *task);
    void markTaskUnread(TaskHandle *task);
    void deleteTask(TaskHandle *task);
    void markContainerRead(TaskContainer *container);
    void deleteContainer(TaskContainer *container);
    bool shutdownTasktopIfInvisible();
    void onCallFinished();
    void newRepository();
    void editRepository(QString repositoryUrl);
    void updateRepositoryConfiguration(QString containerHandle);
    void newQuery(QString repositoryUrl);
    void editQuery(QString containerHandle);
    void initEventHandler();
    void activeTask();
    void deactivateTasks();
    void activateTask(QString identifier);
    void newSupportRequest();
    void cloneQuery(QString identifier);
    void openTimeTrackingDashboard();
    void importTaskList();
    void exportTaskList();

private slots:
    void projectChanged(ProjectExplorer::Project *project);
    void fieldsUpdated();
    void onError(const TicketError &error);
    void createNewQuery(int result);
    void queryComplete(int done, int total);

private:
    TicketQuery queryFromSettings();
    void changeConfiguration(ITicketBackendConfiguration *conf);
    void setTicketModel(BaseTicketItemModel *model, TicketQuery query = TicketQuery());
    void restoreSettings();
    void createInitialQuery(bool forceReset = false);
    void autoQueryDone(QString queryLabel);
    void refreshQueriesFromModel(BaseTicketItemModel *model, QString queryTitle);
    ProjectExplorer::Project *m_project;
    QSortFilterProxyModel *m_proxy;
    QUrl m_currentBackendUrl;
    TaskListControllerPrivate *d;
    TracCreateQueryDialog *queryDialog;
    QString currentContainerIdentifier;
    QFutureInterface<void> *progressObject;
    bool initialQueriesCreated;
    QString lastAutoCreatedQuery;
    QSettings m_settings;
    TaskListRoot *m_currentRoot;
    QList<TaskContainer*> m_currentContainers;
    bool m_configurationReset;
    //QMap<QString, Ticket*> m_tickets;
    QMap<QString, BaseTicketItemModel*> m_models;
    QStringList m_statuses, m_types;
};

#endif // TRACTASKLISTCONTROLLER_H
